package com.hs.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hs.entity.dto.Comment;
import com.hs.entity.dto.Notice;
import com.hs.entity.dto.TeamEmp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    @Select("<script>" +
            "SELECT c.*, t.team_name, t.team_img, u.username, u.avatar " +
            "FROM comment c " +
            "LEFT JOIN teams t ON c.team_id = t.id " +
            "LEFT JOIN users u ON c.user_id = u.id " +
            "<where>" +
            "  <if test='ew.sqlSegment != null and ew.sqlSegment.trim() != \"\"'>" +
            "    ${ew.sqlSegment}" +
            "  </if>" +
            "</where>" +
            "ORDER BY c.create_time DESC" +
            "</script>")
    List<Comment> selectListWithTeamAndUser(@Param("ew") QueryWrapper<Comment> queryWrapper);

    @Update("UPDATE comment SET like_count = like_count + 1 WHERE id = #{id}")
    void incrementLikeCount(@Param("id") Integer id);
}
